package com.punai.config.sqlitedao;


import com.punai.common.exception.ServiceException;
import com.punai.common.utils.sqlite.SqliteUtils;
import com.punai.config.domain.ConfigLinkTemplateFormacte;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ConfigTemplateLinkFormacategoryRepository {
	@Autowired
	private SqliteUtils sqliteUtils;
	
	public void save(ConfigLinkTemplateFormacte configLinkTemplateFormacte) {
		String sql="INSERT INTO tab_config_link_template_formacategory(template_id,formacategory_code) VALUES(?,?)";
		int rownumber=0;
		Object[] args=null;
		args=new Object[]{
				configLinkTemplateFormacte.getTemplateId(),
				configLinkTemplateFormacte.getFormatcategoryCode()
		};
		
		rownumber= sqliteUtils.execute(sql, args);
		if(rownumber==0) {
			throw new ServiceException("sqlite.message.addException");
		 }
	}
	public void save(List<ConfigLinkTemplateFormacte> list)  {
		for (ConfigLinkTemplateFormacte templateLinkFormacategory : list) {
			save(templateLinkFormacategory);
		}
	}
	public void deleteByFormacategoryCode(String code)  {
		String sql="delete from tab_config_link_template_formacategory where formacategory_code='"+code+"'";
		int rownumber = sqliteUtils.execute(sql);
	}
}
